package com.jueban.Dto;

import com.jueban.model.user.User;
import com.jueban.util.Enum.Gender;
import com.jueban.util.Enum.JobType;
import com.jueban.util.Enum.UserType;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.BeanUtils;

import javax.validation.constraints.Pattern;
import java.util.Date;

@Data
public class UserDto {

    private Integer id;

    private Integer age;

    @NotBlank
    private String username;

    private String password;

    private String idNumber;

    private Date birthday;

    @NotBlank(message = "部门不能为空")
    private String department;

    @NotBlank(message = "姓名不能为空")
    private String name;

    @Pattern(regexp = "male|female")
    private String gender;

    @Pattern(regexp = "admin|teacher|student")
    private String userType;

    private String jobType;

    private String phone;

    private String email;

    public void registerTransfer(User user) {
        BeanUtils.copyProperties(this, user, "gender", "userType");
        user.setGender(Gender.valueOf(gender));
        user.setUserType(UserType.valueOf(userType));
    }

    public void infoTransfer(User user) {
        BeanUtils.copyProperties(this, user, "gender"
                , "userType", "username", "password");
        user.setGender(Gender.valueOf(gender));

    }
    public void infoUserNotPassword(User user) {
        BeanUtils.copyProperties(this, user, "password");
        user.setGender(Gender.valueOf(gender));
        if(jobType != null && "".equals(jobType))
        {
            user.setJobType(JobType.valueOf(jobType));
        }
        user.setUserType(UserType.valueOf(userType));
    }
    public void infoUser(User user) {
        BeanUtils.copyProperties(this, user);
        user.setGender(Gender.valueOf(gender));
        if(jobType != null && !jobType.equals(""))
        {
            user.setJobType(JobType.valueOf(jobType));
        }
        user.setUserType(UserType.valueOf(userType));
    }

        /*

  @Pattern(regexp = "党政办|纪监审计处|组织宣传部|人事处|教务处|科研处|" +
            "学生处|财务处|招生办|总务处|保卫处|基础思政部|图书馆|信息中心|团委|" +
            "电气工程系|机械工程系|经济管理系|计算机系|外语系|后勤保障处|纪检监察审计处")
    * */
}
